import { _decorator, Component, Node, tween, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('testMove')
export class testMove extends Component {
    pos = v3();
    initpos = v3();
    @property
    spd = 2;

    isHide = false;

    protected onLoad(): void {
        this.initpos.set(this.node.position);
        this.pos.set(this.node.position);
    }
    protected onEnable(): void {
    }

    update(dt: number) {
        this.pos.z += dt * this.spd;
        if (this.pos.z > 7) {
            this.pos.z = this.initpos.z;
            this.delayShow();
        }
        this.node.setPosition(this.pos);
    }

    delayShow() {
        this.node.active = false;
        tween(this.pos).delay(2).call(() => {
            this.node.active = true;
        }).start();
    }
}


